//
//  XQChartView.m
//  XQChartDemo
//
//  Created by xq on 2024/6/15.
//

#import "XQChartView.h"
#import <Masonry/Masonry.h>
#import <AAChartKit/AAGlobalMacro.h>
#import <AAChartKit/AAChartKit.h>
#import <AAChartKit/AASeriesElement.h>
#import "XQChartWKScriptMessageHandlerModel.h"

static NSString * const kUserContentMessageNameChartClicked = @"click";
static NSString * const kUserContentMessageNameChartMoveOver = @"moveOver";
static NSString * const kUserContentMessageNameChartDefaultSelected = @"defaultSelected";

@interface XQChartView () <AAChartViewEventDelegate, WKScriptMessageHandler>

@property (nonatomic, strong) AAChartView *chartView;

/// 选中下标
/// -1表示未选中
@property (nonatomic, assign) NSInteger selectIndex;

@property (nonatomic, strong) AAClickEventMessageModel *selectMessage;

/// NSNumber 或者 AADataElement 类型, NSNull
@property (nonatomic, copy) NSArray *chartData;

@property (nonatomic, strong) XQChartWKScriptMessageHandlerModel *wkSMHModel;

/// 是否允许移动
@property (nonatomic, assign) BOOL enableMove;

@end

@implementation XQChartView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //        CGFloat chartViewWidth  = self.view.frame.size.width;
        //        CGFloat chartViewHeight = self.view.frame.size.height - 250;
        
        self.points = [NSMutableArray array];
        self.selectIndex = -1;
        self.minY = 0;
        self.maxY = 100;
        
        self.minX = 0;
        self.maxX = 100;
        
        self.overflowY = 5;
        self.overflowX = 5;
        
        self.chartView = [AAChartView new];
        //        self.chartView.frame = CGRectMake(0, 60, 0, 0);
        [self addSubview:self.chartView];
        
        [self.chartView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        
        // 禁止滚动
        self.chartView.scrollEnabled = NO;
        
        self.wkSMHModel = [XQChartWKScriptMessageHandlerModel new];
        
        self.chartView.delegate = self;
        //        self.chartView.chartSeriesHidden = YES;
        
        // 外部去调用吧
//        [self drawChartModel];
        
//        [self configWebView];
        
        UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(respondsToPan:)];
        pan.maximumNumberOfTouches = 1;
        [self.chartView addGestureRecognizer:pan];
    }
    return self;
}

- (void)configWebView {
    /*
     试了一下，也没啥用...还是监听不了手机移动的xy，看了一下 AAChartView.html 源码，也就 Clicked 和 MoveOver
     */
    
    // 搞个中间件，防止循环引用
    // delegate 和 webview 不能共用
    self.wkSMHModel.delegate = self;
    WKWebViewConfiguration *chartConfiguration = self.chartView.configuration;
    [chartConfiguration.userContentController addScriptMessageHandler:self.wkSMHModel name:kUserContentMessageNameChartClicked];
    [chartConfiguration.userContentController addScriptMessageHandler:self.wkSMHModel name:kUserContentMessageNameChartMoveOver];
//    [chartConfiguration.userContentController addScriptMessageHandler:self.wkSMHModel name:kUserContentMessageNameChartDefaultSelected];
    
    __weak typeof(self) weakSelf = self;
    self.chartView.didFinishLoadBlock = ^(AAChartView *aaChartView) {
        [weakSelf.delegate xqChartViewDidFinishLoad:weakSelf];
    };
}

//- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//    [super touchesMoved:touches withEvent:event];
//    // wxq 通过 touch 下标，进行自己控制选择还是其他
//    for (UITouch *obj in event.allTouches.allObjects) {
//        if ([obj.view isKindOfClass:[XQChartView class]]) {
//            //            NSLog(@"touchesMoved %@ %@", touches, event);
//            NSLog(@"touchesMoved %@", NSStringFromCGPoint([obj locationInView:self]));
//        }
//    }
//}

/// 更新点位置
/// @param points CGPoint类型
- (void)refreshWithPoints:(NSArray *)points {
    [self refreshWithPoints:points selectIndex:-1];
}

/// 更新点位置
/// @param points CGPoint类型
- (void)refreshWithPoints:(NSArray *)points selectIndex:(NSUInteger)selectIndex {
    CGPoint lastPoint = CGPointMake(0, 0);
    for (int i = 0; i < points.count; i++) {
        NSValue *v = points[i];
        CGPoint p = v.CGPointValue;
        if (p.x < lastPoint.x) {
            NSLog(@"不能比上一个 x 小");
            return;
        }
        
        lastPoint = p;
    }
    
    self.points = points.mutableCopy;
    self.selectIndex = selectIndex;
    if (self.selectIndex >= points.count) {
        self.selectIndex = -1;
    }else if (self.selectIndex < 0) {
        self.selectIndex = -1;
    }
    [self refreshChartViewWithIsAdd:YES];
}

/// 传入 point，返回点数据
- (AADataElement *)getDataElementWithPoint:(CGPoint)point selected:(BOOL)selected {
    AADataElement *model = AADataElement.new
        .markerSet(AAMarker.new
                   .radiusSet(@8) // 圆点半径
                   //                               .symbolSet(AAChartSymbolTypeCircle)// 曲线点类型
                   //                               .fillColorSet(AAColor.whiteColor)//点的填充色(用来设置折线连接点的填充色)
                   //                               .lineWidthSet(@5)//外沿线的宽度(用来设置折线连接点的轮廓描边的宽度)
                   //外沿线的颜色(用来设置折线连接点的轮廓描边颜色，当值为空字符串时，默认取数据点或数据列的颜色)
                   //                   .lineColorSet(AAColor.redColor)
                   
                   //                                      .statesSet(AAMarkerStates.new
                   //                                                 .selectSet(AAMarkerSelect.new
                   //                                                            .enabledSet(NO) // 是否允许选中
                   //                                                            )
                   //                                                 )
                   )
        .ySet([NSNumber numberWithFloat:point.y])
        .xSet([NSNumber numberWithFloat:point.x])
    ;
    
    // 是否选中
    model.selected = @(selected);
    
    return model;
}

- (AADataElement *)getHideDataElementWithPoint:(CGPoint)point {
    AADataElement *model = AADataElement.new
        .markerSet(AAMarker.new
                   .radiusSet(@0) // 圆点半径
                   )
    //        .ySet([NSNumber numberWithFloat:point.y])
        .xSet([NSNumber numberWithFloat:point.x])
    ;
    
    return model;
}

- (void)drawChartModel {
    [self drawChartModelWithRefresh:NO];
}

- (void)drawChartModelWithRefresh:(BOOL)refresh {
    NSArray *arr = @[
        AASeriesElement.new
        //                .colorSet(@"#FF0000") // 所有颜色..
        //                .negativeColorSet(@"#FF0000")
        //                .negativeFillColorSet(@"#00FF00")
        //                .borderColorSet(@"#00FF00")
        //                .fillColorSet(@"#0000FF")
            .allowPointSelectSet(YES) // 是否可以选择
        
        //                    .lineWidthSet(@30) // 线条大小
        //                    .dataLabelsSet(AADataLabels.new // 显示每个点的数据..
        //                                    .backgroundColorSet(@"#FF0000")
        //                    )
        
        //                .markerSet(AAMarker.new // 点的样式设置
        //            //                                .radiusSet(@(10)) // 半径大小
        //            //                                .fillColorSet(@"#00FF00") // 点的默认颜色
        //            //                                .lineColorSet(@"#FF0000") // 选中的周围颜色
        //                .statesSet(AAMarkerStates.new
        //                .selectSet(AAMarkerSelect.new // 设置选中样式
        //                .fillColorSet(@"#FF0000") // 选中颜色
        //            )
        //            )
        //            )
        
        //            .statesSet(AAStates.new // ?
        ////            .selectSet(AASelect.new
        ////        //                                            .colorSet(@"#FF0000")
        ////        //                                            .borderColorSet(@"#00FF00")
        ////            .enabledSet(YES) // 允许选择
        ////        )
        //        )
        
            .dataSet(@[
                // 最初点
                [self getHideDataElementWithPoint:CGPointMake(0, 0)],
                
                // 最终点
                [self getHideDataElementWithPoint:CGPointMake(self.maxX + self.overflowX, 0)],
            ]), // 数据
    ];
    [self drawChartModelWithSeries:arr refresh:refresh];
}

- (void)drawChartModelWithSeries:(NSArray *)series refresh:(BOOL)refresh {
    AAChartModel *aaChartModel = AAChartModel.new
        .markerRadiusSet(@0) // 圆点半径
        .chartTypeSet(AAChartTypeLine)//设置图表的类型(这里以设置的为折线面积图为例)
    ;
    
    // 设置数据
    aaChartModel.series = series;
    
    // 最大最小值
    aaChartModel.yAxisMin = @(self.minY);
    // 要加一点...不然会看不到
    aaChartModel.yAxisMax = @(self.maxY + self.overflowY);
    
    // xy轴是否显示
    aaChartModel.xAxisVisible = self.xAxisVisible;
    aaChartModel.yAxisVisible = self.yAxisVisible;
    
    // 选中提示框是否显示
    aaChartModel.tooltipEnabled = NO;
    
    // 底部图例是否显示
    aaChartModel.legendEnabled = NO;
    
    // 动画时间
    aaChartModel.animationDuration = @0;
    
    // 背景颜色
    if (self.chartBackgroundColor != NULL) {
        aaChartModel.backgroundColor = self.chartBackgroundColor;
    }
    
    //    aaChartModel.borderRadius = @(60);
    
    AAOptions *aaOptions = aaChartModel.aa_toAAOptions;
    //        获取用户点击位置的代码逻辑, 参考:
    //        * https://www.highcharts.com/forum/viewtopic.php?t=11983
    //        * https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getBoundingClientRect
    //
    //        JSON.stringify(), 参考:
    //        * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
    aaOptions.plotOptions.series
            .pointSet(AAPoint.new
                      .eventsSet(AAPointEvents.new
                                 .clickSet([self configureClickOrMoveOverEventJSEventWithUserContentMessageName:kUserContentMessageNameChartClicked])
                                 .mouseOverSet([self configureClickOrMoveOverEventJSEventWithUserContentMessageName:kUserContentMessageNameChartMoveOver])
                                 ));
    
    if (refresh) {
//        [self.chartView aa_refreshChartWithChartModel:aaChartModel];
        [self.chartView aa_refreshChartWithOptions:aaOptions];
    }else {
//        [self.chartView aa_drawChartWithChartModel:aaChartModel];
        [self.chartView aa_drawChartWithOptions:aaOptions];
    }
}

- (void)refreshChartView {
    [self refreshChartViewWithIsAdd:NO];
}

- (void)refreshChartViewWithIsAdd:(BOOL)isAdd {
    NSMutableArray *dataArr = [NSMutableArray array];
    // 最初点
    [dataArr addObject:[self getHideDataElementWithPoint:CGPointMake(0, 0)]];
    
    // 中间数据
//    NSLog(@"point len: %lu", (unsigned long)self.points.count);
//    NSLog(@"points: %@", self.points);
    for (int i = 0; i < self.points.count; i++) {
        NSValue *v = self.points[i];
        CGPoint p = v.CGPointValue;
        BOOL s = self.selectIndex == i;
//        NSLog(@"index: %d, select: %d", i, s);
        [dataArr addObject:[self getDataElementWithPoint:p selected:s]];
    }
    
    // 最终点
    // 要加多一点，不然会看不到
    [dataArr addObject:[self getHideDataElementWithPoint:CGPointMake(self.maxX + self.overflowX, 0)]];
    
    NSArray *arr = @[
        AASeriesElement.new
        //                .colorSet(@"#FF0000") // 所有颜色..
        //                .negativeColorSet(@"#FF0000")
        //                .negativeFillColorSet(@"#00FF00")
        //                .borderColorSet(@"#00FF00")
        //                .fillColorSet(@"#0000FF")
//            .allowPointSelectSet(YES) // 是否可以选择
        
        //                    .lineWidthSet(@30) // 线条大小
        //                    .dataLabelsSet(AADataLabels.new // 显示每个点的数据..
        //                                    .backgroundColorSet(@"#FF0000")
        //                    )
        
        //                .markerSet(AAMarker.new // 点的样式设置
        //            //                                .radiusSet(@(10)) // 半径大小
        //            //                                .fillColorSet(@"#00FF00") // 点的默认颜色
        //            //                                .lineColorSet(@"#FF0000") // 选中的周围颜色
        //                .statesSet(AAMarkerStates.new
        //                .selectSet(AAMarkerSelect.new // 设置选中样式
        //                .fillColorSet(@"#FF0000") // 选中颜色
        //            )
        //            )
        //            )
        
//            .statesSet(AAStates.new
//            .selectSet(AASelect.new
//            .enabledSet(YES) // 已选择当前线
//        )
//        )
        
            .dataSet(dataArr), // 数据
    ];
    
    if (isAdd) {
        // 先为空，再为正常值
        // 这里是因为有一个bug，先手动点击选中，再去添加点，是有问题的，会看上去选中了两个点
        NSArray *arr1 = @[
            AASeriesElement.new
                .dataSet(@[
                    [self getHideDataElementWithPoint:CGPointMake(0, 0)],
                    [self getHideDataElementWithPoint:CGPointMake(self.maxX + self.overflowX, 0)]
                ])
        ];
        [self.chartView aa_onlyRefreshTheChartDataWithChartModelSeries:arr1 animation:NO];
        [self.chartView aa_onlyRefreshTheChartDataWithChartModelSeries:arr animation:NO];
    }else {
        [self.chartView aa_onlyRefreshTheChartDataWithChartModelSeries:arr animation:NO];
    }
//    [self.chartView aa_onlyRefreshTheChartDataWithOptionsSeries:arr animation:NO];
}

/// 选中的点，改变 Y
- (BOOL)changeSelectPointXY:(CGPoint)xy {
    if (self.selectIndex >= 0 && self.selectIndex < self.points.count) {
        CGFloat minX = 0;
        CGFloat maxX = 100;
        
        if (self.points.count > 1) {
            // x 不能小于上一个数，也不能大于下一个数
            if (self.selectIndex != 0) {
                NSValue *v = self.points[self.selectIndex - 1];
                minX = v.CGPointValue.x;
            }
            
            if (self.selectIndex < self.points.count - 1) {
                NSValue *v = self.points[self.selectIndex + 1];
                maxX = v.CGPointValue.x;
            }
            
            if (xy.x < minX) {
                xy.x = minX;
            }
            
            if (xy.x > maxX) {
                xy.x = maxX;
            }
            
//            if (xy.x < minX || xy.x > maxX) {
//                return NO;
//            }
        }
        
        if (xy.y < self.minY) {
            xy.y = self.minY;
        }
        
        if (xy.y > self.maxY) {
            xy.y = self.maxY;
        }
        
        self.points[self.selectIndex] = [NSValue valueWithCGPoint:xy];
        [self refreshChartView];
    }else {
        // 未选中点
        self.selectIndex = -1;
        return NO;
    }
    
    return YES;
}

/// 自动根据当前情况添加点
- (void)autoAddPoint {
    if (self.points.count == 0) {
        [self.points addObject:[NSValue valueWithCGPoint:CGPointMake(self.minX, self.minY)]];
        self.selectIndex = 0;
        [self refreshChartViewWithIsAdd:YES];
    }else if (self.points.count == 1) {
        [self.points addObject:[NSValue valueWithCGPoint:CGPointMake(self.maxX, self.maxY)]];
        self.selectIndex = 1;
        [self refreshChartViewWithIsAdd:YES];
    }else {
        if (self.selectIndex >= 0 && self.selectIndex < self.points.count) {
            // 选中和下一个中间
            NSUInteger index = 0;
            NSUInteger rIndex = 0;
            if (self.selectIndex == self.points.count - 1) {
                index = self.selectIndex - 1;
                rIndex = self.selectIndex;
            }else {
                index = self.selectIndex + 1;
                rIndex = index;
            }
            
            NSValue *v = self.points[self.selectIndex];
            CGPoint sPoint = v.CGPointValue;
            NSValue *v1 = self.points[index];
            CGPoint p = v1.CGPointValue;
            
            CGPoint r = CGPointMake(0, 0);
            CGFloat x = fabs(sPoint.x - p.x) / 2;
            if (sPoint.x > p.x) {
                r.x = p.x + x;
            }else {
                r.x = sPoint.x + x;
            }
            
            CGFloat y = fabs(sPoint.y - p.y) / 2;
            if (sPoint.y > p.y) {
                r.y = p.y + y;
            }else {
                r.y = sPoint.y + y;
            }
            
            [self.points insertObject:[NSValue valueWithCGPoint:r] atIndex:rIndex];
            self.selectIndex = rIndex;
            [self refreshChartViewWithIsAdd:YES];
        }else {
            // 在中间插入
            self.selectIndex = self.points.count/2;
            [self autoAddPoint];
        }
    }
}

/// 添加点
- (void)addPointWithPoint:(CGPoint)point {
    [self.points addObject:[NSValue valueWithCGPoint:point]];
    self.selectIndex = self.points.count - 1;
    [self refreshChartViewWithIsAdd:YES];
}

/// 删除选中点
- (void)removeSelectPoint {
    if (self.selectIndex >= 0 && self.selectIndex < self.points.count) {
        [self.points removeObjectAtIndex:self.selectIndex];
        
        // 赋值下一个选中目标
        if (self.points.count >= 3) {
            self.selectIndex = self.points.count/2;
        }else if (self.points.count == 0) {
            self.selectIndex = -1;
        }else {
            self.selectIndex = 0;
        }
    }else {
        [self.points removeAllObjects];
        self.selectIndex = -1;
    }
    
    [self refreshChartView];
}

/// 选中上一个点
- (void)selectPrePoint {
    if (self.points.count == 0) {
        return;
    }
    
    if (self.selectIndex < 0) {
        self.selectIndex = self.points.count - 1;
        [self refreshChartViewWithIsAdd:YES];
    }else if (self.selectIndex == 0) {
        
    }else {
        self.selectIndex -= 1;
        [self refreshChartViewWithIsAdd:YES];
    }
}

/// 选中下一个点
- (void)selectNextPoint {
    if (self.points.count == 0) {
        return;
    }
    
    if (self.selectIndex < 0) {
        self.selectIndex = 0;
        [self refreshChartViewWithIsAdd:YES];
    }else if (self.selectIndex == self.points.count - 1) {
        
    }else {
        self.selectIndex += 1;
        [self refreshChartViewWithIsAdd:YES];
    }
}

#pragma mark - responds

- (void)respondsToPan:(UIPanGestureRecognizer *)panGesture {
    
//    CGPoint tp = [panGesture translationInView:self.chartView];
    CGPoint tp = [panGesture locationInView:self.chartView];
    //    NSLog(@"pan: %@", NSStringFromCGPoint(tp));
    /*
     不知道是否跟着字大小改变...
     x固定50高左右
     y固定50宽左右
     150高，100
     300高，250
     700高，650
     */
    CGFloat subx = 50;
    CGFloat subMinY = 10; // 10 是头顶多出来那一点
    CGFloat suby = 50 + subMinY;
    
    tp.x -= subx;
    tp.y -= subMinY;
    
    if (tp.x < 0) {
        tp.x = 0;
    }
    
    if (tp.y < 0) {
        tp.y = 0;
    }
    
    CGPoint p = CGPointMake(self.bounds.size.width - subx, self.bounds.size.height - suby);
    CGPoint xy = CGPointMake((tp.x/p.x) * self.maxX, ((p.y - tp.y)/p.y) * self.maxY);
    if (xy.x < 0) {
        xy.x = 0;
    }
    
    if (xy.y < 0) {
        xy.y = 0;
    }

    switch (panGesture.state) {
        case UIGestureRecognizerStateBegan: {
            // 看是否在某个点范围内，在的话，就允许移动
            if (self.selectIndex < 0 || 
                self.points.count == 0 ||
                self.selectIndex >= self.points.count) {
                return;
            }
            
            if (self.enableMove) {
                return;
            }
            
            NSValue *v = self.points[self.selectIndex];
            CGPoint point = [v CGPointValue];
            
//            NSLog(@"began xy: %@ %@", NSStringFromCGPoint(xy), NSStringFromCGPoint(point));
            
            if (fabs(xy.x - point.x) < 15 &&
                fabs(xy.y - point.y) < 15) {
                self.enableMove = YES;
            }
        }
            break;
            
        case UIGestureRecognizerStateChanged: {
            if (!self.enableMove) {
                return;
            }
            
//            NSLog(@"move xy: %@", NSStringFromCGPoint(xy));
            
            [self changeSelectPointXY:xy];
        }
            break;
            
        case UIGestureRecognizerStateEnded: {
            if (self.enableMove) {
//                NSLog(@"end xy: %@", NSStringFromCGPoint(xy));
                
                self.enableMove = NO;
                [self changeSelectPointXY:xy];
            }
        }
            break;
            
        default:
            break;
    }
}

- (NSString *)configureClickOrMoveOverEventJSEventWithUserContentMessageName:(NSString *)userContentMessageName {
    return [NSString stringWithFormat:@AAJSFunc((function() {
        let svgElement = aaGlobalChart.series[0].data[this.index].graphic.element;
        let rect = svgElement.getBoundingClientRect();
        let messageBody = {
            "name": this.series.name,
            "y": this.y,
            "x": this.x,
            "category": this.category,
            "index": this.index,
            "DOMRect": JSON.stringify(rect),
        };
        window.webkit.messageHandlers.%@.postMessage(messageBody);
    })),userContentMessageName];
}

#pragma mark - AAChartViewEventDelegate

- (void)aaChartViewDidFinishLoad:(AAChartView *)aaChartView {
//    NSLog(@"aaChartViewDidFinishLoad");
    [self.delegate xqChartViewDidFinishLoad:self];
}

- (void)aaChartView:(AAChartView *)aaChartView clickEventWithMessage:(AAClickEventMessageModel *)message {
//    NSLog(@"clickEventWithMessage %lu, %@, %@, %@", (unsigned long)message.index, message.x, message.y, message.offset);
    
    // 除去原点
    NSUInteger index = message.index - 1;
    self.selectMessage = message;
    if (index == self.selectIndex) {
        self.selectIndex = -1;
    }else {
//        NSLog(@"%d", index);
        self.selectIndex = index;
    }
}

- (void)aaChartView:(AAChartView *)aaChartView moveOverEventWithMessage:(AAMoveOverEventMessageModel *)message {
    // 监听移动到某区域，不是监听手指移动...
//    NSLog(@"moveOverEventWithMessage %@ %lu, %@, %@, %@, %@", message.name, (unsigned long)message.index, message.x, message.y, message.offset, message.category);
}

- (void)aaChartView:(AAChartView *)aaChartView didReceiveScriptMessage:(WKScriptMessage *)message {
//    NSLog(@"didReceiveScriptMessage");
    
}



#pragma mark - WKScriptMessageHandler

- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
    NSLog(@"name: %@", message.name);
    if ([message.name isEqualToString:kUserContentMessageNameChartClicked]) {
        NSDictionary *clickEventMessage = message.body;
        NSLog(@"%@", clickEventMessage);
        
    } else if ([message.name isEqualToString:kUserContentMessageNameChartMoveOver]) {
        NSDictionary *moveOverEventMessage = message.body;
        NSLog(@"%@", moveOverEventMessage);
    } else if ([message.name isEqualToString:kUserContentMessageNameChartDefaultSelected]) {
        NSDictionary *defaultSelectedEventMessage = message.body;
        NSLog(@"%@", defaultSelectedEventMessage);
    }
}

#pragma mark - set

- (void)setSelectIndex:(NSInteger)selectIndex {
    if (_selectIndex == -1) {
        if (_selectIndex == selectIndex) {
            return;
        }
    }
    
    if (_selectIndex != selectIndex) {
        _selectIndex = selectIndex;
    }
    
    if (_selectIndex >= self.points.count) {
        _selectIndex = -1;
    }
    
    if (_selectIndex < 0) {
        _selectIndex = -1;
    }
    
    CGPoint p = CGPointMake(0, 0);
    if (_selectIndex >= 0 && _selectIndex < self.points.count) {
        NSValue *v = self.points[_selectIndex];
        p = v.CGPointValue;
//        NSLog(@"setSelectIndex: %@", v);
    }
    [self.delegate xqChartView:self index:_selectIndex point:p select:selectIndex != -1];
}

@end
